<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>数据库生成</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>数据库快速生成</legend>
</fieldset>
<div style="width: 700px;" align="center">
    <div class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">生成类路径</label>
            <div class="layui-input-block">
                <input type="text" name="outputDir" lay-verify="required" autocomplete="off"
                       placeholder="例如：E:\project\weigh\src\main  不要包含包名、最多到java目录即可"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">author名称</label>
            <div class="layui-input-block">
                <input type="tel" name="author" lay-verify="required" value="mybatis-plus" lay-reqtext="请输入author名称"
                       placeholder="请输入"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">模块名称</label>
            <div class="layui-input-block">
                <input type="tel" name="moduleName" placeholder="例如 user .为包名分隔符"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">请输入包名</label>
            <div class="layui-input-block">
                <input type="tel" name="parent" lay-verify="required" placeholder="例如包名 com.fmy.dbgenerate"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">实体父类</label>
            <div class="layui-input-block">
                <input type="tel" name="superEntityClass"
                       value="com.liuyi.mybatisplus.plus.base.BaseEntity"
                       placeholder="例如包名 IBaseService"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">mapper父类</label>
            <div class="layui-input-block">
                <input type="tel" name="superMapperClass"
                       value="com.liuyi.mybatisplus.plus.base.IBaseMapper"
                       placeholder="例如包名 IBaseService"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">service父类</label>
            <div class="layui-input-block">
                <input type="tel" name="superServiceClass"
                       value="com.liuyi.mybatisplus.plus.base.IBaseService"
                       placeholder="例如包名 IBaseService"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">表名前戳</label>
            <div class="layui-input-block">
                <input type="tel" name="tablePrefix" value="tb_" placeholder="例如包名 tb_"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">swagger2</label>
            <div class="layui-input-block">
                <input type="checkbox" value="true" lay-text="开启|关闭" name="swagger2" lay-skin="switch">
            </div>
        </div>
        <div class="layui-form-item">
            <div id="transfer"></div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>
</div>

<script th:src="@{/static/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/static/jquery-3.4.1.min.js}" charset="utf-8"></script>
<script th:inline="javascript">
    var tables = [[${tables}]]
    layui.use(['form', 'layedit', 'laydate', 'transfer'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , transfer = layui.transfer

        //渲染
        transfer.render({
            elem: '#transfer'  //绑定元素
            , data: tables
            , showSearch: true
            , title: ['表名', "生成表"]
            , parseData: function (res) {
                return {
                    "value": res //数据值
                    , "title": res //数据标题
                    , "disabled": false  //是否禁用
                    , "checked": false //是否选中
                }
            }
            , id: 'tables' //定义索引
        });

        //监听提交
        form.on('submit(submit)', function (data) {
            var tables = transfer.getData('tables');
            if (tables.length <= 0) {
                layer.msg('请选择需要生成的表');
                return false;
            }
            var tablesStr = [];
            tables.forEach(function (item) {
                tablesStr.push(item.value);
            });
            data.field.tables = tablesStr.join(',');
            $.ajax({
                type: 'POST',
                url: '/generate',
                data: data.field,
                success: function (res) {
                    if (res == true) {
                        layer.msg('生成成功');
                    } else {
                        layer.msg('生成失败');
                    }
                }

            })
            return false;
        });
    });
</script>
</body>
</html>